package shuxue

import "fmt"

func Add() {

	fmt.Println("请输入第一个数字：")
	var firstNum float64
	fmt.Scanln(&firstNum)
	fmt.Println("请输入第二个数字：")
	var secondNum float64
	fmt.Scanln(&secondNum)
	fmt.Println("请输入第三个数字：")
	var thirdNum float64
	fmt.Scanln(thirdNum)
	fmt.Println("请输入第四个数字：")
	var fourthNum float64
	fmt.Scanln(&fourthNum)
	fmt.Println(firstNum+secondNum, "的结果是：", add(firstNum, secondNum, thirdNum, fourthNum))

}

func Chengfa() {

	fmt.Println("请输入第一个数字：")
	var firstNum float64
	fmt.Scanln(&firstNum)
	fmt.Println("请输入第二个数字：")
	var secondNum float64
	fmt.Scanln(&secondNum)
	resualt := firstNum * secondNum
	fmt.Println(firstNum*secondNum, "的结果是：", resualt)
}

func Jianfa() {

	fmt.Println("请输入第一个数字：")
	var firstNum float64
	fmt.Scanln(&firstNum)
	fmt.Println("请输入第二个数字：")
	var secondNum float64
	fmt.Scanln(&secondNum)
	resualt := firstNum - secondNum
	fmt.Println(firstNum-secondNum, "的结果是：", resualt)

}

func Chufa(a, b int) (resualt int, errorstr error) {
	if b == 0 {
		resualt = 0
		return 0, fmt.Errorf("除数不能为0")
	} else {
		resualt = a / b
		return resualt, nil
	}

}

func ChufaDemo() {
	var chushu, beichushu int
	fmt.Println("请输入除数")
	fmt.Scanln(&chushu)
	fmt.Println("请输入被除数")
	fmt.Scanln(&beichushu)
	jieguo, err := Chufa(beichushu, chushu)
	if err != nil {
		fmt.Println("错误！！！", err)
	} else {
		fmt.Println("结果是 : ", jieguo)
	}
}

func add(allNum ...float64) (resualt float64) {
	for i := 0; i < len(allNum); i++ {
		resualt = resualt + allNum[i]
	}
	return resualt

}
